package processes;

import to.MaterialTO;
import to.ProductTO;
import util.DateUtil;
import util.MaterialParser;
import util.ProductParser;

public class DyeingMachine extends Machine {
	public DyeingMachine(MachineManager machineManager, String machineId) {
		super(2500,1000, machineManager, machineId);
		setLineName("Dyeing Machine");
	}
	
	@Override
	public void beforeManufacture() {
		MaterialParser mp = MaterialParser.getInstance();
		MaterialTO dye = mp.readMaterial(getWork().getColorId());
		int size = getWork().getSize();
		dye.setQuantity(dye.getQuantity()-size);
		mp.writeMaterial(dye);
		mp.returnKey();
		
	}
	
	@Override
	public void afterManufacture() {
		currentProduct.setDyeingQuality(generateQuality());
		currentProduct.setDyeingDate(DateUtil.getInstance().getCurrentTimeString());
		currentProduct.setDyeingId(getMachineId());
		currentProduct.setDyeingTime((int)(DateUtil.getInstance().getCurrentTimeLong()-getStartTime()));
		ProductParser pp = ProductParser.getInstance();
		pp.writeProduct(machineManager.getNextDir(), currentProduct);
	}
}
